<template>
    <div class="container">
        <div class="title">
            <span>信息设置</span>
        </div>
        <el-divider></el-divider>
        <br/>
        <el-form label-width="100px"
                 :model="form"
                 status-icon
                 ref="form"
                 @submit.native.prevent>
            <el-form-item label="图片" prop="img_id">
                <upload-imgs
                        ref="uploadEle"
                        :value="imgValue"
                        :rules="rules"
                        :multiple="true"
                        :min-num="1"
                        :max-num="1"
                />
                <div>推荐上传 </div>
            </el-form-item>
            <el-form-item label="地址" prop="address">
                <el-input size="medium"
                          v-model="form.address"
                          placeholder="请填写地址"></el-input>
            </el-form-item>
            <el-form-item label="联系方式" prop="phone">
                <el-input size="medium"
                          v-model="form.phone"
                          placeholder="请填写联系方式"></el-input>
            </el-form-item>
            <el-form-item label="地址坐标" prop="coordinate">
                <el-input size="medium" v-model="form.coordinate" placeholder="请填写地址坐标"></el-input>
                <a href="https://lbs.qq.com/tool/getpoint/" target="_blank">腾讯坐标拾取网址</a>
            </el-form-item>
            <el-form-item label="门店简介" prop="content">
                <el-input size="medium"
                          v-model="form.content"
                          type="textarea"
                          :rows="5"
                          placeholder="请输入门店简介"></el-input>
            </el-form-item>
            <el-form-item class="submit">
                <el-button type="primary" @click="submitForm('form')">保 存</el-button>
                <el-button @click="resetForm('form')">重 置</el-button>
            </el-form-item>
        </el-form>
    </div>
</template>
<script>
import admin from '@/models/admin'
import User from '@/lin/models/user'
import UploadImgs from '@/components/base/upload-imgs'

export default {
  components: {
    UploadImgs,
  },
  data() {
    return {
      imgValue: [],
      form: {
        id: '',
        lin_user_id: '',
        address: '',
        coordinate: '',
        phone: '',
        img_id: '',
        content: '',
      },
      rules: {
        maxSize: 0.2,
      },
    }
  },
  mounted() {
    this.getAdminUser()
  },
  methods: {
    async getAdminUser() {
      const res = await User.getInformation()
      this.form.lin_user_id = res.linUserId
      this.getSystem()
    },
    // 获取详情
    async getSystem() {
      const adminInfo = await admin.getAdminInfo(this.form.lin_user_id)
      if (adminInfo) {
        this.imgValue = [{
          delete: false,
          id: adminInfo.id,
          imgId: adminInfo.img_id,
          display: adminInfo.img.url,
        }]
        this.form = {
          id: adminInfo.id,
          address: adminInfo.address,
          coordinate: adminInfo.coordinate,
          lin_user_id: this.form.lin_user_id,
          traffic: adminInfo.traffic,
          phone: adminInfo.phone,
          img_id: adminInfo.img_id,
          content: adminInfo.content,
        }
      }
    },
    // eslint-disable-next-line no-unused-vars
    async submitForm(formName) {
      const self = this
      const imgValue = await self.$refs.uploadEle.getValue()
      // eslint-disable-next-line no-unused-vars
      const info = {
        id: self.form.id,
        address: self.form.address,
        coordinate: self.form.coordinate,
        lin_user_id: self.form.lin_user_id,
        img_id: Number(imgValue[0].imgId),
        phone: self.form.phone,
        content: self.form.content,
      }
      try {
        // eslint-disable-next-line no-unused-vars
        const res = await admin.createAdmin(info)
        if (res.error_code === 0) {
          this.$message.success(`${res.msg}`)
        }
      } catch (error) {
        console.log(error)
      }
    },
    // 重置表单
    resetForm() {
      this.getSystem()
    },
    change(val) {
      this.form.contact_us = val
    },
  },
}
</script>

<style lang="scss" scoped>
    .el-divider--horizontal {
        margin: 0
    }

    .container {
        .title {
            height: 59px;
            line-height: 59px;
            color: $parent-title-color;
            font-size: 16px;
            font-weight: 500;
            text-indent: 40px;

            .back {
                float: right;
                margin-right: 40px;
                cursor: pointer;
            }
        }

        .wrap {
            padding: 20px;
        }

        .submit {
            float: left;
        }
    }
</style>
